package com.example.demo.web;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class PromethusController {

    /**
     * 收到数据
     * {"alerts":[{"status":"firing","labels":{"alertname":"InstanceDown","group":"example","instance":"exporter:9100","job":"prometheus","monitor":"first-monitor","severity":"page"},"annotations":{"description":"exporter:9100 of job prometheus has been down for more than 5 minutes.","summary":"Instance exporter:9100 down"},"startsAt":"2021-06-30T06:02:41.248Z","endsAt":"0001-01-01T00:00:00Z","generatorURL":"http://8b14f6b9be91:9090/graph?g0.expr=up+%3D%3D+0&g0.tab=1","fingerprint":"730bc9ea0c6f3562"}],"commonLabels":{"alertname":"InstanceDown","group":"example","instance":"exporter:9100","job":"prometheus","monitor":"first-monitor","severity":"page"},"externalURL":"http://73617deacb84:9093","groupLabels":{},"receiver":"web\\.hook","truncatedAlerts":0,"version":"4","commonAnnotations":{"description":"exporter:9100 of job prometheus has been down for more than 5 minutes.","summary":"Instance exporter:9100 down"},"groupKey":"{}:{}","status":"firing"}
     * @param jsonObject
     * @return
     */
    @PostMapping("alert")
    public String gotAlertMessage(@RequestBody JSONObject jsonObject) {
        log.info("data: {}", jsonObject.toJSONString());
        return "success";
    }

}
